package com.rain.shoppingscienceproj.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rain.shoppingscienceproj.module.TypeDataInfo;
import com.rain.shoppingscienceproj.R;

import java.util.List;

public class ProductTypeAdapter extends BaseAdapter {

    List<TypeDataInfo> list;
    private Context mContext;
    private LayoutInflater inflater;

    public ProductTypeAdapter(List<TypeDataInfo> list, Context context) {
        this.list = list;
        this.mContext = context;
        this.inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        if(list == null){
            return 0;
        }else{
            return list.size();
        }

    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            holder = new MyViewHolder();
            convertView = inflater.inflate(R.layout.product_type_item, null);
            holder.tv_key = convertView.findViewById(R.id.tv_key);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        TypeDataInfo typeProduct = list.get(position);
        holder.tv_key.setText(typeProduct.getTitle());
        return convertView;
    }

    class MyViewHolder {
        TextView tv_key;
    }
}
